package com.game.model;

import com.game.util.ImageUtil;
import com.game.util.PropertiesUtil;

import java.awt.*;

/**
 * @Author: tjc
 * @description
 * @Date Created in 22:12 2021-12-01
 */
public class Number extends Module {
    private int value;

    public Number(int value) {
        checkValue(value);
        this.value = value;
        setLocalX(PropertiesUtil.loadInt("stage.width"));
        setLocalY(PropertiesUtil.loadInt("stage.length"));
    }

    public int getValue() {
        return value;
    }

    public boolean add(int b) {
        checkValue(b);
        value += b;
        if (value / 10 > 1) {
            value = value % 10;
            return true;
        }
        return false;
    }

    private boolean checkValue(int val) {
        if (val >= 10 || val < 0) {
            throw new RuntimeException("Number is between 0 to 9!");
        }
        return true;
    }

    @Override
    public void draw(Graphics g) {
        g.drawImage(ImageUtil.numberImages[value], localX, localY, SIZE_X, SIZE_Y, null);
    }
}
